package com.itheima.demo7;

import java.io.*;
import java.net.Socket;

public class ClientDemo3 {
    public static void main(String[] args) throws IOException {
        //TCP协议，发送数据
        //上传文件

        //1.创建Socket对象
        Socket socket = new Socket("127.0.0.1",10086);

        //2.读取本地文件，并上传到服务器
        BufferedReader bis = new BufferedReader(new FileReader("a.txt"));
        OutputStream bos = socket.getOutputStream();

        String line;
        while ((line = bis.readLine()) != null){
            System.out.println(line);
            bos.write(line.getBytes());
        }

        //释放输出完成信号
        socket.shutdownOutput();

        //接收数据
        BufferedReader br =new  BufferedReader(new InputStreamReader(socket.getInputStream()));
        System.out.println(br.readLine());


        //释放资源
        bis.close();
        socket.close();
    }
}
